/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sembr.vtk.data.input;

import vtk.vtkConeSource;
import vtk.vtkDoubleArray;
import vtk.vtkPolyData;

/**
 *
 * @author adriano
 */
public class Cone extends SourceBase {
    
    private vtkConeSource coneSource;
    private double radius;
    private double height;
    private double[] center;
    private double angle;
    private double[] direction;
    private int resolution;
    private boolean isCapping;
    private vtkPolyData polyData;
    private double material;

    /**
     * @return the coneSource
     */
    public vtkConeSource getConeSource() {
        return coneSource;
    }

    /**
     * @param coneSource the coneSource to set
     */
    public void setConeSource(vtkConeSource coneSource) {
        this.coneSource = coneSource;
        this.coneSource.SetRadius(radius);
        this.coneSource.SetHeight(height);
        this.coneSource.SetCenter(center);
        this.coneSource.SetAngle(angle);
        this.coneSource.SetDirection(direction);
        this.coneSource.SetResolution(resolution);
        
        if (isCapping)
            this.coneSource.CappingOn();
        else
            this.coneSource.CappingOff();
        
        this.coneSource.Update();
        applyMaterial();
    }
    
     /**
     * @return the material
     */
    public double getMaterial() {
        return material;
    }

    /**
     * @param material the material to set
     */
    public void setMaterial(double material) {
        this.material = material;
    }
    
    private void applyMaterial() {
        polyData = triangulatePolyData(this.coneSource.GetOutput());
        int nrOfCells = polyData.GetNumberOfCells(); 
        vtkDoubleArray scalars = new vtkDoubleArray();
        
        scalars.SetNumberOfComponents(1);
        scalars.SetNumberOfValues(nrOfCells);
        
        for (int i = 0; i < nrOfCells; i++) {
            scalars.SetValue(i, getMaterial());
        }
        
        polyData.GetCellData().SetScalars(scalars);
        polyData.Update();
    }
    /**
     * @return the radius
     */
    public double getRadius() {
        return radius;
    }

    /**
     * @param radius the radius to set
     */
    public void setRadius(double radius) {
        this.radius = radius;
    }

    /**
     * @return the height
     */
    public double getHeight() {
        return height;
    }

    /**
     * @param height the height to set
     */
    public void setHeight(double height) {
        this.height = height;
    }

    /**
     * @return the center
     */
    public double[] getCenter() {
        return center;
    }

    /**
     * @param center the center to set
     */
    public void setCenter(double center[]) {
        this.center = center;
    }

    /**
     * @return the angle
     */
    public double getAngle() {
        return angle;
    }

    /**
     * @param angle the angle to set
     */
    public void setAngle(double angle) {
        this.angle = angle;
    }

    /**
     * @return the direction
     */
    public double[] getDirection() {
        return direction;
    }

    /**
     * @param direction the direction to set
     */
    public void setDirection(double[] direction) {
        this.direction = direction;
    }

    /**
     * @return the resolution
     */
    public int getResolution() {
        return resolution;
    }

    /**
     * @param resolution the resolution to set
     */
    public void setResolution(int resolution) {
        this.resolution = resolution;
    }

    /**
     * @return the isCapping
     */
    public boolean isCapping() {
        return isCapping;
    }

    /**
     * @param isCapping the isCapping to set
     */
    public void setIsCapping(boolean isCapping) {
        this.isCapping = isCapping;
    }
    
    /**
     * @return the polyData
     */
    @Override
    public vtkPolyData getPolyData() {
        return polyData;
    }

    /**
     * @param polyData the polyData to set
     */
    public void setPolyData(vtkPolyData polyData) {
        this.polyData = polyData;
    }
}
